<?php
/**
*
* 功能描述（管理控制器）
*
* @author suoya <jlusuoya@gmail.com>
* @version 1
*/

class CtrlLogin extends CtrlBase
{
	public $paramCheck = array(
		"login" => array(
			"username" => array("POST", "must", "trim", "notempty"),
			"password" => array("POST", "must", "trim", "notempty"),
		),
	);

	public $perm = array('allow', "index.php");

	function ToLogin()
	{
		return RT_TPL;
	}

	function Login()
	{
		if(array_key_exists("bind", $_SESSION))
			unset($_SESSION['bind']);
		$obj = $this->GetModel("admin");
		$data = $obj->Login($this->params['username'], $this->params['password']);
		if(!$data)
			$msg = "用户不存在或者密码错误";
		else
		{
			$_SESSION['admin'] = array(
				"id" => $data['id'],
				"name" => $data['name'],
				"logintime" => time(0),
				"mobile" => $data['mobile'],
				"truename" => $data['truename'],
				"perms" => array(
					'none' => false,
					'allow' => true, 	//登录相关，默认有权限
					'cake' => $data['p_cake'],	//蛋糕管理
					'order' => $data['p_order'],	//订单管理
					'prod' => $data['p_prod'],	//生产管理
					'dely' => $data['p_dely'],	//配送管理
					'index' => true,			//主页
					'msg' => $data['p_msg'],	//留言管理
					'user' => $data['p_user'],	//会员管理
					'log' => $data['p_log'],	//系统日志
					'adm' => $data['p_adm'],	//管理员管理
				),
			);
			$this->LoadInfo();
			$msg = "登录成功";
		}
		$this->assign("msg", $msg);
		return RT_MSG;
	}

	function Logout()
	{
		if(array_key_exists("admin", $_SESSION))
			unset($_SESSION['admin']);
		if(array_key_exists("bind", $_SESSION))
			unset($_SESSION['bind']);
		$this->LoadInfo();
		$this->assign("msg", "退出成功");
		return RT_MSG;
	}
}

